<?php

/**
 * 验证接口字段均不为空
 * @param $req
 * @param $columnArray
 * @return bool
 */
function validateColumn($req, $columnArray) {

    $access = true;

    for ($i=0; $i<count($columnArray); $i++) {

        if (!isset($req[$columnArray[$i]])) {
            $access = false;
            break;
        }
    }

    return $access;

}

/**
 * 检验是否是手机号
 * @param $mobile
 * @return bool
 */
function isMobile($mobile) {
    if (!is_numeric($mobile)) {
        return false;
    }
    return preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', $mobile) ? true : false;
}

/**
 * 检查商品json字符串格式
 * @param $json
 * @param $goodsList
 * @return bool
 */
function checkGoodsIdJson($json, $goodsList) {

    if (!count($json)) {
        return false;
    }

    $goodsIdArr = array();
    foreach ($goodsList as $key=>$val) {
        $goodsIdArr[$key]['id'] = $val['id'];
    }

    $flag = true;
    foreach ($json as $key=>$val) {

        if (!array_key_exists('goods_id', $val)) {
            $flag = false;
            break;
        }

        if (!deep_in_array($val['goods_id'], $goodsIdArr)) {
            $flag = false;
            break;
        }
    }

    return $flag;

}
